package cn.edu.zjut.bean;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * @author XiaoFeng
 * @version 1.0
 * @Description Create by 2021/12/3 14:38
 */

public class itemOrder implements IItemOrder, InitializingBean, DisposableBean {
    private IItem item;
    private int numItems;

    public void init() {
        System.out.println("正在执行初始化方法 init...");
    }
    public void MyDestroy(){
        System.out.println("正在执行我的默认销毁方法 destory...");
    }

    public itemOrder() {
        System.out.println("Spring 实例化 ItemOrder...");
    }

    public void incrementNumItems() {
        setNumItems(getNumItems() + 1);
    }

    public void cancelOrder() {
        setNumItems(0);
    }

    public double getUnitCost() {
        return getItem().getCost();
    }

    public double getTotalCost() {
        return (getNumItems() * getUnitCost());
    }

    public IItem getItem() {
        return item;
    }

    public void setItem(IItem item) {
        System.out.println("Spring 注入 item...");
        this.item = item;
    }

    public int getNumItems() {
        return numItems;
    }

    public void setNumItems(int numItems) {
        System.out.println("Spring 注入 numItems...");
        this.numItems = numItems;
    }

    public void afterPropertiesSet() throws Exception {
        System.out.println("正在执行初始化方法 afterPropertiesSet...");
    }

    public void destroy() throws Exception {
        System.out.println("bean 销毁之前的行为");
    }
}
